﻿using System;
using System.Collections.Generic;
using System.Text;
using Abp.Dependency;
using Abp.Events.Bus.Entities;
using Abp.Events.Bus.Handlers;
using Abp.RemoteEventBus;
using Abp.Runtime.Caching;
using FwProject.BrandInfo.Dto;
using FwProject.Comm;
using FwProject.Core.AppVersion;
using FwProject.Shop.Dto;
using FwProject.ShoppingMall.BrandInfo;
using FwProject.ShoppingMall.Com;

namespace FwProject.EventHandle
{
    public class ShopOrderDetailsHandle : IEventHandler<EntityChangedEventData<ShopOrderDetails>>, IEventHandler<EntityCreatedEventData<ShopOrderDetails>>, ITransientDependency
    {
        public readonly ICacheManager _catchmanager;
        public IRemoteEventBus remoteEventBus { get; set; }//缓存对象
        public ShopOrderDetailsHandle(ICacheManager catchmanager)
        {
            _catchmanager = catchmanager;
            remoteEventBus = NullRemoteEventBus.Instance;
        }
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="eventData">Event data.</param>
        public void HandleEvent(EntityChangedEventData<ShopOrderDetails> eventData)
        {
            if (eventData.Entity.DeliveryStatus == DeliveryStatus.已发货)
            {
                ///生成商品基本信息
                var shopappcatcheventDate = new RemoteEventData(RemoteTypeHelp.TYPESEARCH)
                {
                    Data = { [RemoteTypeHelp.MODELID] = eventData.Entity.ShopproductId, [RemoteTypeHelp.MODELNAME] = nameof(ShopProductAppDto) }
                };
                remoteEventBus.Publish(RemoteTypeHelp.TOPICAPPSYSTEMSEARCH, shopappcatcheventDate);

                ///生成列表的基本信息
                var shopproductListAppDto = new RemoteEventData(RemoteTypeHelp.TYPESEARCH)
                {
                    Data = { [RemoteTypeHelp.MODELID] = eventData.Entity.ShopproductId, [RemoteTypeHelp.MODELNAME] = nameof(ShopProductListAppDto) }
                };
                remoteEventBus.Publish(RemoteTypeHelp.TOPICAPPSYSTEMSEARCH, shopproductListAppDto);
            }
        }
        public void HandleEvent(EntityCreatedEventData<ShopOrderDetails> eventData)
        {
            var shopproductListAppDto = new RemoteEventData(RemoteTypeHelp.TYPEREMOVECAR)
            {
                Data = { [RemoteTypeHelp.MODELID] = eventData.Entity.Id, [RemoteTypeHelp.MODELNAME] = nameof(ShopOrderDetails) }
            };
            remoteEventBus.Publish(RemoteTypeHelp.TOPICAPPUSERCAR, shopproductListAppDto);
        }
       }
    }
